/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package shellCommands;

import Sessions.EcomAdminRemote;
import Sessions.EcomCustomersRemote;
import java.util.StringTokenizer;

/**
 *
 * @author SOGOBA
 */
public class OutputCommand implements InterShell{
    private ContextCommande cxtCmd;

    public OutputCommand(ContextCommande cxtCmd) {
        this.cxtCmd = cxtCmd;
    }

    @Override
    public Commands getName() {
        return Commands.output;
    }

    @Override
    public String getShortDescription() {
        return "output HTML|XML|TEXT|JSON change the output format of data";
    }

    @Override
    public void execute(String cmd,EcomAdminRemote ecomAdmin,EcomCustomersRemote ecomCust) {
        StringTokenizer st = new StringTokenizer(cmd, " ");
        // Ignore the command name.
        st.nextToken();
        // There should be at least one string.
        if (st.countTokens()==1){
            String str=st.nextToken().trim();
            switch (str) {
                case "XML":
                    cxtCmd.setVar("output", "XML");
                    break;
                case "TEXT":
                    cxtCmd.setVar("output", "TEXT");
                    break;
            }
            System.out.println("The format is correctly change to "+str);
            }
        else {
            System.out.println("Incorrect number of arguments");
        }
    }
    }   
